// pages/SuSong/choose/choose.js
import request from '../../../utils/config.js';
import util from '../../../utils/util.js';
const app = getApp();
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    custInfo:{},
    show_xiashu:false,
    isSign:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function () {
    this.setData({
      custInfo: app.globalData.custInfo,
    });
    let show_xiashu = false;
    if (app.globalData.loginUserInfo.roles.includes('ROLE_CustomInfoQuery')) {
      show_xiashu = true
    }
    if (app.globalData.loginUserInfo.dataConstraintList.ROLE_CustomInfoQuery){
      if (JSON.parse(app.globalData.loginUserInfo.dataConstraintList.ROLE_CustomInfoQuery)[0].type=='self'){
        show_xiashu=false
      }else{
        show_xiashu = true
      }
    }
    let ROLE_LawyerAssistApply = app.globalData.loginUserInfo.roles.includes('ROLE_LawyerAssistApply')?true:false;
    let ROLE_CustomInfoManage = app.globalData.loginUserInfo.roles.includes('ROLE_CustomInfoManage') ? true : false;
    this.setData({ show_xiashu, ROLE_LawyerAssistApply, ROLE_CustomInfoManage});
  },

  onLoad: function (options) {
    this.setData({
      isSign: options.isSign=='Y'?true:false
    })
  },
  goNext:function(e){
    // console.log(e)
    let target = e.currentTarget.dataset.type;
    let info = this.data.custInfo;
    if (target=='xiashu'){
      wx.redirectTo({
        url: '../signList/signList',
      })
    } else if (target == 'khlxr'){
      info.custVo.statusFlag = "khlxr";
      app.globalData.custInfo = info;
      wx.redirectTo({
        url: '../addcusLinkman/addcusLinkman'
      })
    } else if (target == 'xscg'){
      info.custVo.statusFlag = "xscg";
      app.globalData.custInfo = info;
      wx.redirectTo({
        url: '../addCollection/addCollection',
      })
    } else if (target == 'goJdjl') {
      info.custVo.statusFlag = "jdjl";
      app.globalData.custInfo = info;
      wx.redirectTo({
        url: '../addCollection/addCollection',
      })
    } else if (target == 'golsxz') {
      info.custVo.statusFlag = "golsxz";
      app.globalData.custId = info.custVo.custId;
      app.globalData.custInfo = info;
      wx.redirectTo({
        url: '../addCounsel/addCounsel?flag=first',
      })
    } else if (target == 'goMessage') {
      this.setData({ modalForInput: true})
    } else if (target == 'signIn') {
      app.globalData.custInfo = info;
      wx.redirectTo({
        url: '../signIn/signIn',
      })
    }
  },
  mseeageTimeChange: function (e) {
    console.log(e)
    if (e.currentTarget.dataset.datetype === 'date') {
      this.setData({
        message_date: e.detail.value
      })
    } else if (e.currentTarget.dataset.datetype === 'time') {
      this.setData({
        message_time: e.detail.value
      })
    } else if (e.currentTarget.dataset.datetype === 'desc') {
      this.setData({
        messageDesc: e.detail.value
      })
    }
  },
  canclemessage: function () {
    this.setData({ modalForInput: false })
  },
  confirmmessage: function () {
    if (!this.data.message_date) {
      wx.showToast({ title: '请选择时间', icon: 'none', duration: 800 });
      return;
    }
    if (!this.data.message_time) {
      wx.showToast({ title: '请选择日期', icon: 'none', duration: 800 });
      return;
    }
    if (!this.data.messageDesc) {
      wx.showToast({ title: '请填写描述', icon: 'none', duration: 800 });
      return;
    }
    let sendData = {
      content: this.data.messageDesc,
      remindTime: this.data.message_date.replace(/-/g, '') + this.data.message_time.replace(/:/g, '') + '00',
    }
    console.log(sendData)
    let _this = this;
    // return
    wx.showLoading({ title: ' ', mask: true })
    request.requestMisApi('post', "custs/" + this.data.custInfo.custVo.custId + "/remindingMessages", sendData, (res) => {
      console.log(res);
      wx.hideLoading()
      if (res.code == '00') {
        _this.setData({ modalForInput: false });
        wx.showToast({ title: res.msg, icon: 'success' })
      } else {
        wx.showToast({ title: res.msg, icon: 'none' })
      }
    }, (res) => {
      wx.hideLoading()
      console.log("接口错误=", res)
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // }
})